package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsRegionMapper;
import com.qf.pojo.DtsRegion;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author mkr
 * @version V1.0
 * @Project java2203-mkr
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/21 10:35
 */
@Service
public class RegionServiceImpl implements RegionService {

    @Autowired
    private DtsRegionMapper regionMapper;

    @Override
    public IPage<DtsRegion> queryDistrictPage(String name, Integer code, Integer page, Integer limit) {

        //1、创建分页对象
        //参数1：当前页，参数2：每页显示多少条数据
        IPage<DtsRegion> iPage = new Page<>(page , limit);

        //2、封装查询对象
        QueryWrapper<DtsRegion> queryWrapper = new QueryWrapper<>();

        //3、判断查询条件是否为空
        if (!StringUtils.isEmpty(name)){
            queryWrapper.eq("name", name);
        }
        if (code != null){
            queryWrapper.eq("code", code);
        }

        //4、查询并返回
        IPage<DtsRegion> resultPage = regionMapper.selectPage(iPage, queryWrapper);

        return resultPage;
    }
}
